package org.cuatrovientos.erp.dao;

import java.util.List;

import org.cuatrovientos.erp.domain.Pais;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget;
import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget;

public class PaisDAO {

	@SessionTarget
	Session session;

	@TransactionTarget
	Transaction transaction;

	public void guadgarOActualizarPais(Pais pais) {
		try {
			session.saveOrUpdate(pais);
		} catch (Exception e) {
			transaction.rollback();
			e.printStackTrace();
		}
	}

	public void eliminarPais(Long id) {
		try {
			Pais pais = (Pais) session.get(Pais.class, id);
			session.delete(pais);
		} catch (Exception e) {
			transaction.rollback();
			e.printStackTrace();
		}
	}

	@SuppressWarnings("unchecked")
	public List<Pais> listarPaises() {
		List<Pais> paises = null;
		try {
			paises = session.createQuery("from Pais").list();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		
		return paises;
	}

	
	public Pais listarPaisPorId(Long id) {
		Pais pais = null;
		try {
			pais = (Pais) session.get(Pais.class, id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return pais;
	}

}
